#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n;
	cin >> n;
	string s;
	for (int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		s += c;
	}
	int count0 = count(s.begin(), s.end(), '0');
	int count1 = count(s.begin(), s.end(), '1');
	if (count0 == 0 || count1 == 0) cout << "YES" << endl;
	else
	{
		if (s.find("100") != string::npos || s.find("001") != string::npos) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}